<?php
/**
 * AWFLogController - Ajax Web File Log Route Controller class
 * 
 * This is the controller for AWFLogRoute.
 * It holds the action that is called with AJAX to display the AWFLog file.
 * 
 * @author Maurizio Domba <mdomba@gmail.com>
 * @version "0.3" 2012-02-29 15:30 mdomba
 */

class AWFLogController extends CController
{
	/**
	 * Action called to display the AWFLog file.
	 * This action disables logging (self logging) so that we don't
	 * get the log for the request to display the log.
	 */
	public function actionIndex()
	{
		$app = Yii::app();
		if($app->getRequest()->getIsAjaxRequest())
		{
			foreach($app->log->routes as $route)
			{
				if($route instanceof AWFLogRoute)
				{
					$route->enabled = false;	//.. disable self logging
					$logFile = $route->logPath . DIRECTORY_SEPARATOR . $route->logFile;
					readfile($logFile);
				}
			}
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}
}